﻿package mortal.game.view.copy.ChallengeCopy
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import __AS3__.vec.*;
    import flash.utils.*;
    import mortal.game.cache.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.copy.ChallengeCopy.data.*;

    public class ChallengeCopyCache extends Object
    {
        private var _challengDic:Dictionary;
        public var residuettimes:int;
        public var isMop:Boolean;
        public var mopTower:int;
        public var isInChallengeCopy:Boolean;

        public function ChallengeCopyCache()
        {
            return;
        }// end function

        public function get challengeDic() : Dictionary
        {
            var _loc_1:ChallengeData = null;
            var _loc_2:Vector.<TChallengeCopy> = null;
            var _loc_3:TChallengeCopy = null;
            var _loc_4:TChallengeCopy = null;
            if (this._challengDic == null)
            {
                this._challengDic = new Dictionary();
                _loc_2 = ChallengeCopyConfig.instance.challengeCopyList;
                for each (_loc_3 in _loc_2)
                {
                    
                    _loc_1 = new ChallengeData(_loc_3);
                    if (this._challengDic[_loc_3.tower] == null)
                    {
                        this._challengDic[_loc_3.tower] = new Array();
                    }
                    _loc_4 = ChallengeCopyConfig.instance.getDataByTowerAndSectionAndDif(_loc_3.tower, _loc_3.section, 1);
                    this._challengDic[_loc_3.tower][(_loc_3.section - 1)] = new ChallengeData(_loc_4);
                    (this._challengDic[_loc_3.tower][(_loc_3.section - 1)] as ChallengeData).passLevel = 0;
                }
            }
            return this._challengDic;
        }// end function

        public function isClearSection(param1:int, param2:int) : Boolean
        {
            return (this._challengDic[param1][(param2 - 1)] as ChallengeData).currentSectionMaxLevel == (this._challengDic[param1][(param2 - 1)] as ChallengeData).passLevel;
        }// end function

        public function getCanEnterSectionByTower(param1:int) : int
        {
            var _loc_4:int = 0;
            var _loc_2:* = this._challengDic[param1];
            var _loc_3:* = (_loc_2[0] as ChallengeData).passLevel;
            var _loc_5:int = 1;
            while (_loc_5 < _loc_2.length)
            {
                
                if (_loc_3 > (_loc_2[_loc_5] as ChallengeData).passLevel)
                {
                    _loc_4 = _loc_5;
                    break;
                }
                _loc_5++;
            }
            return (_loc_4 + 1);
        }// end function

        public function isAllClear() : Boolean
        {
            var _loc_2:Array = null;
            var _loc_3:int = 0;
            var _loc_1:* = Cache.instance.role.roleInfo.level;
            for each (_loc_2 in this._challengDic)
            {
                
                if (_loc_1 >= (_loc_2[0] as ChallengeData).tChallengCopy.towerLimitLv)
                {
                    _loc_3 = 0;
                    while (_loc_3 < _loc_2.length)
                    {
                        
                        if ((_loc_2[_loc_3] as ChallengeData).passLevel == 0)
                        {
                            return false;
                        }
                        _loc_3++;
                    }
                }
            }
            return true;
        }// end function

        public function isLowestDiffcultByChllengeData(param1:ChallengeData) : Boolean
        {
            var _loc_4:ChallengeData = null;
            var _loc_2:* = this.challengeDic[param1.tChallengCopy.tower];
            var _loc_3:Boolean = true;
            if (!param1.passLevel)
            {
                _loc_3 = true;
            }
            else
            {
                for each (_loc_4 in _loc_2)
                {
                    
                    if (!_loc_4.passLevel)
                    {
                        _loc_3 = false;
                        break;
                        continue;
                    }
                    if (_loc_4.tChallengCopy.level < param1.tChallengCopy.level)
                    {
                        _loc_3 = false;
                        break;
                    }
                }
            }
            return _loc_3;
        }// end function

        public function updateChallengInfo(param1:Dictionary) : void
        {
            var _loc_2:Array = null;
            var _loc_3:TChallengeCopy = null;
            var _loc_4:String = null;
            var _loc_5:int = 0;
            for (_loc_4 in param1)
            {
                
                _loc_2 = (param1[_loc_4] as SLevelInfo).levelsInfo;
                _loc_5 = 0;
                while (_loc_5 < _loc_2.length)
                {
                    
                    _loc_3 = ChallengeCopyConfig.instance.getDataByTowerAndSectionAndDif(int(_loc_4), (_loc_5 + 1), _loc_2[_loc_5]);
                    this.challengeDic[_loc_4][_loc_5] = new ChallengeData(_loc_3);
                    (this.challengeDic[_loc_4][_loc_5] as ChallengeData).passLevel = _loc_3.level;
                    _loc_5++;
                }
            }
            return;
        }// end function

        public function getDataByTowerAndSection(param1:int, param2:int) : ChallengeData
        {
            return this.challengeDic[param1][(param2 - 1)] as ChallengeData;
        }// end function

        public function getHightestSectionByTowerAndDic(param1:int, param2:int) : int
        {
            var _loc_5:ChallengeData = null;
            var _loc_3:* = this.challengeDic[param1];
            var _loc_4:* = _loc_3.length;
            var _loc_6:int = 4;
            var _loc_7:* = param2 * 4;
            while (_loc_7 < param2 * 4 + 4)
            {
                
                _loc_5 = _loc_3[_loc_7];
                if (_loc_5.passLevel < _loc_5.currentSectionMaxLevel)
                {
                    _loc_6 = _loc_5.tChallengCopy.section;
                    break;
                }
                _loc_7++;
            }
            _loc_6 = (_loc_6 - 1) % 4 + 1;
            return _loc_6;
        }// end function

        public function getHightestRealSectionByTower(param1:int) : int
        {
            var _loc_4:ChallengeData = null;
            var _loc_6:int = 0;
            var _loc_2:* = this.challengeDic[param1];
            var _loc_3:* = _loc_2.length;
            var _loc_5:* = _loc_2.length + 1;
            while (_loc_6 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_6];
                if (_loc_4.passLevel < _loc_4.currentSectionMaxLevel)
                {
                    _loc_5 = _loc_4.tChallengCopy.section;
                    break;
                }
                _loc_6++;
            }
            return _loc_5;
        }// end function

        public function getHightestSectionByTower(param1:int) : int
        {
            var _loc_4:ChallengeData = null;
            var _loc_6:int = 0;
            var _loc_2:* = this.challengeDic[param1];
            var _loc_3:* = _loc_2.length;
            var _loc_5:* = _loc_2.length + 1;
            while (_loc_6 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_6];
                if (_loc_4.passLevel < _loc_4.currentSectionMaxLevel)
                {
                    _loc_5 = _loc_4.tChallengCopy.section;
                    break;
                }
                _loc_6++;
            }
            _loc_5 = (_loc_5 - 1) % 4 + 1;
            return _loc_5;
        }// end function

        public function getHightestDiffByTower(param1:int) : int
        {
            var _loc_4:ChallengeData = null;
            var _loc_6:int = 0;
            var _loc_2:* = this.challengeDic[param1];
            var _loc_3:* = _loc_2.length;
            var _loc_5:int = 0;
            while (_loc_6 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_6];
                if (_loc_4.passLevel < _loc_4.currentSectionMaxLevel)
                {
                    _loc_5 = _loc_4.tChallengCopy.section;
                    break;
                }
                _loc_6++;
            }
            _loc_5 = (_loc_5 - 1) / 4;
            return _loc_5;
        }// end function

    }
}
